using System.Collections.Generic;
using Microsoft.DirectX;

namespace SharpWind.Scene
{
	public class SceneNode
	{
		private static MatrixStack matrixStack = new MatrixStack();

		private List<SceneNode> childrens = new List<SceneNode>();

		protected Vector3 position = Vector3.Empty;

		protected Vector3 orientation = Vector3.Empty;

		protected Vector3 scale = new Vector3( 1f, 1f, 1f );

		internal void Process()
		{
			matrixStack.Push();
			matrixStack.TranslateLocal( this.position );
			matrixStack.RotateYawPitchRollLocal( this.orientation.X, this.orientation.Y, this.orientation.Z );

			Engine.Instance.Renderer.Device.Transform.World = Matrix.Scaling( this.scale ) * matrixStack.Top;

			Render();
			
			foreach( SceneNode node in this.childrens )
			{
				node.Process();
			}

			matrixStack.Pop();
		}

		public virtual void Render()
		{
		
		}

		public List<SceneNode> Childrens
		{
			get
			{
				return this.childrens;
			}
		}

		public Vector3 Position
		{
			get
			{
				return this.position;
			}
			set
			{
				this.position = value;
			}
		}

		public Vector3 Orientation
		{
			get
			{
				return this.orientation;
			}
			set
			{
				this.orientation = value;
			}
		}

		public Vector3 Scale
		{
			get
			{
				return this.scale;
			}
			set
			{
				this.scale = value;	
			}
		}
	}
}
